package io.renren.modules.title.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.R;
import io.renren.modules.title.entity.ExamTitle;
import io.renren.modules.title.from.TitleFrom;
import io.renren.modules.title.service.ExamTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.UUID;

/**
 * @ClassName ExamTitleController
 * @Author mengjiafeng
 * @Date 2019/9/4 10:40
 **/
@RestController
@RequestMapping("/examTitle")
public class ExamTitleController {
    @Autowired
    private ExamTitleService examTitleService;

    @GetMapping("/getAllTitle")
    public R getAllTitle(Page page,ExamTitle examTitle){
        IPage page1 = examTitleService.page(page,new QueryWrapper<ExamTitle>().like("question",examTitle.getQuestion()));
        return  R.ok().put("titles",page1);
    }
    @GetMapping("/getTitleDetail")
    public R getTitleDetail(String id){
        Map map = examTitleService.getTitleDetail(id);
        return R.ok().put("titleDetail",map);
    }
    @PostMapping("/updateTitle")
    public R updateTitle(@RequestBody TitleFrom titleFrom){
        examTitleService.updateTitle(titleFrom);
        return R.ok("更新成功");
    }
    @PostMapping("/addTitle")
    public R addTitle(@RequestBody TitleFrom titleFrom){
//        String uuid = UUID.randomUUID().toString();
//        titleFrom.setId(uuid);
        examTitleService.addTitle(titleFrom);
        return R.ok("添加成功");
    }
    //删除题目或批量删除题目
    @PostMapping("/deleteTitle")
    public R addTitle(@RequestBody Long[] userIds){
//        String uuid = UUID.randomUUID().toString();
//        titleFrom.setId(uuid);
        examTitleService.deleteTitle(userIds);
        return R.ok("删除成功");
    }
    @GetMapping("/updateAuditState")
    public R updateAuditState(String id){
        examTitleService.update(new UpdateWrapper<ExamTitle>().set("audit_state","1").eq("id",id));
        return R.ok("更新状态成功");
    }

}
